package com.devin.dao;


import com.devin.pojo.Permission;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.cache.decorators.LruCache;

import java.util.List;

@Mapper
@CacheNamespace(blocking = true,eviction = LruCache.class,flushInterval = 0L,size=1024,readWrite = true)
public interface PermissionMapper {
    @Select("select * from permission")
    @Options(useCache = true)
    List<Permission> getPermissions();

    @Select(" select * from permission where id in (select permissionId from role_permission where roleId=#{roleId})")
    @Options(useCache = true)
    List<Permission> getPermissionsByRoleId(Integer roleId);

    @Select(" select * from permission where id not in (select permissionId from role_permission where roleId=#{roleId})")
    @Options(useCache = true)
    List<Permission> getPermissions2Json(Integer roleId);

    @Insert("insert into permission values(null,#{permissionName},#{url})")
    void addPermission(Permission permission);

    @Delete("delete from permission where id =#{permissionId}")
    void delPermission(Integer permissionId);
}
